<template>
  <div class="login_container">
    <div class="login_box">
      <div class="login_logo">
        <img src="../assets/logo.png" alt="" />
      </div>
      <el-form
        ref="user"
        class="login_form"
        :model="user"
        :rules="loginFormRules"
      >
        <el-form-item prop="username">
          <el-input
            placeholder="请输入用户名"
            prefix-icon="el-icon-user"
            v-model="user.username"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
            v-model="user.password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item class="login_btn">
          <el-button type="info" @click="reset">重置</el-button>
          <el-button type="success" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      user: {
        username: "admin",
        password: "123456",
      },
      // 表单验证规则对象
      loginFormRules: {
        // 设置验证规则的名称
        username: [
          {
            required: true,
            message: "请输入用户名",
          },
          {
            min: 3,
            max: 8,
            message: "用户名长度在3到6个字符",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
          },
          {
            min: 6,
            max: 16,
            message: "密码长度在6到16个字符",
          },
        ],
      },
    };
  },
  methods: {
    login() {
        this.$router.push('main')
    },
    reset() {
      this.$refs.user.resetFields();
    },
  },
};
</script>
<style lang="less" scoped>
.login_container {
  background: #2b4b6b;
  height: 100%;
  .login_box {
    width: 450px;
    height: 300px;
    background: #fff;
    border-radius: 5px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    .login_logo {
      width: 90px;
      height: 90px;
      box-shadow: 0 0 1px rgb(52, 52, 52);
      border-radius: 100%;
      padding: 5px 8px;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      background: #fff;
      img {
        width: 100%;
        height: 100%;
        border-radius: 100%;
      }
    }
  }
  .login_form {
    position: absolute;
    bottom: 20px;
    width: 100%;
    padding: 0px 20px;
    box-sizing: border-box;
    .login_btn {
      display: flex;
      justify-content: space-around;
    }
  }
}
</style>